package com.project.erp.dao.fobcost;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.project.erp.common.dao.HibernateDao;
import com.project.erp.common.utils.Page;
import com.project.erp.model.fobcost.FobCostDetail;

@Repository
public class FobCostDetailDao extends HibernateDao<FobCostDetail, Long> {
	/**
	 * 根据条件查询总记录
	 * @param page
	 * @param fobCostDetail
	 * @return
	 */
	public Page<FobCostDetail> getFobCostDetailPageBySearch(Page<FobCostDetail> page,FobCostDetail fobCostDetail){
		if(null == fobCostDetail){
			page = this.getAll(page);
		}
		List<Criterion> list = new ArrayList<Criterion>();
		if(StringUtils.isNotEmpty(fobCostDetail.getItemEn())){
			Criterion itemEn = Restrictions.ilike("itemEn",fobCostDetail.getItemEn(),MatchMode.ANYWHERE);
			list.add(itemEn);
		}
		if(StringUtils.isNotEmpty(fobCostDetail.getItemZn())){
			Criterion itemZn = Restrictions.ilike("itemZn",fobCostDetail.getItemZn(),MatchMode.ANYWHERE);
			list.add(itemZn);
		}
		
		if(fobCostDetail.getStartTime() != null){
			Criterion startDate = Restrictions.ge("createTime", fobCostDetail.getStartTime());
			list.add(startDate);
		}
		
		if(fobCostDetail.getEndTime() != null){
			Criterion endTime = Restrictions.le("createTime",fobCostDetail.getEndTime());
			list.add(endTime);
		}
		
		page = this.findPage(page,list.toArray(new Criterion[list.size()]));
		
		return page;
	}
}
